package enterprise.web.tookit.tipoevento;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

import org.apache.log4j.Logger;

import enterprise.web.tookit.email.Email;

/**
 * 
 * @since 02/09/2012
 * 
 * @author regisrocha
 * 
 * @description Classe para mapeamento da entidade enterprisewebtoolkit_db.TipoEvento
 * 
 */
@Entity(name = "tipoevento")
public class TipoEvento implements Serializable {

	/**
	 * serial version
	 */
	private static final long serialVersionUID = 7824665157151583010L;

	/**
	 * LOG
	 */
	private final static Logger log = Logger.getLogger(TipoEvento.class);

	private Integer id;
	private Email email;

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the email
	 */
	@JoinColumn(name = "idEmail", referencedColumnName = "id")
	@OneToOne(cascade = CascadeType.ALL)
	public Email getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(Email email) {
		this.email = email;
	}

	@Override
	public String toString() {
		final StringBuilder toString = new StringBuilder();

		toString.append(" ID: " + this.id);

		if (this.email != null) {
			toString.append(" EMAIL: " + this.email.toString());
		}

		return toString.toString();
	}

	@PostLoad
	public void postLoad() {
		log.info("Loading TipoEvento: " + this.toString());
	}

	@PrePersist
	public void prePersist() {
		log.info("Persisting TipoEvento: " + this.toString());
	}

	@PostPersist
	public void postPersist() {
		log.info("TipoEvento persisted, ID: " + this.id);
	}

	@PreUpdate
	public void preUpdate() {
		log.info("Pre updating TipoEvento: " + this.toString());
	}

	@PostUpdate
	public void postUpdate() {
		log.info("TipoEvento updated, iD: " + this.id);
	}

	@PreRemove
	public void preRemove() {
		log.info("Pre removing TipoEvento: " + this.toString());
	}

	@PostRemove
	public void postRemove() {
		log.info("TipoEvento Removed, ID: " + this.id);
	}

}
